<?php

Class DateFormat
{
	public static function formatDateTime($datetime,  $dateWidth='medium', $timeWidth='medium')
	{
		if(self::isValidTimeStamp($datetime))
		{
			$timestamp = $datetime;
			$datetime = date('Y-m-d H:i:s',$datetime);
		}
		else{
			$timestamp = strtotime($datetime);
			$datetime = date('Y-m-d H:i:s',$timestamp);
		}
		
		$str = Yii::app()->dateFormatter->formatDateTime($datetime,$dateWidth,$timeWidth);
		if (Yii::app()->language === 'th')
		{
			$year = date('Y',$timestamp);
			$datetime = str_replace($year,(int)$year + 543,$str);
			$datetime = str_replace('ค.ศ.','พ.ศ.',$str);
			return $datetime;
		}
	}
	
	protected static function isValidTimeStamp($timestamp)
	{
		return ((string) (int) $timestamp === $timestamp) 
        && ($timestamp <= PHP_INT_MAX)
        && ($timestamp >= ~PHP_INT_MAX);
	}
}